package com.sakura.system.controller.gldctroller.console.login;

import com.sakura.system.coommon.Result;
import com.sakura.system.entity.gld.User;
import com.sakura.system.service.impl.gldimpl.UserServiceImpl;
import com.sakura.system.utils.SM4Utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * gld
 * 2023-3-14
 * 用户登陆及注册
 */
@Slf4j
//解决跨域问题
@CrossOrigin
@RestController
@RequestMapping("${app.router.url}"+"/user")
public class LoginController {
    @Autowired
    private UserServiceImpl service;

    @PostMapping("/login")
    public Result login(@RequestBody User user){
//        log.info(user.getPassword());
//        获取加密用户名进行数据解密
        String s = SM4Utils.decryptData_CBC(user.getPassword(), "GJwsXX_BzW=gJWJW", "ZkR_SiNoSOFT=568");
        log.info(s);
        user.setPassword(s);
        User loginUser = service.login(user);

        return Result.success(loginUser);
    }



    @PostMapping("/register")
    public Result register(@RequestBody User user){
        service.add(user);
        return Result.success();
    }
}
